package com.lineage.server.serverpackets;

import com.lineage.server.datatables.MapsGroupTable;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.templates.L1MapsLimitTime;
import java.util.Collection;
import java.util.Iterator;

public class S_PacketBoxMapTimer extends ServerBasePacket {
  private byte[] _byte = null;
  
  public S_PacketBoxMapTimer(L1PcInstance pc) {
    Collection<L1MapsLimitTime> mapLimitList = MapsGroupTable.get().getGroupMaps().values();
    writeC(250);
    writeC(159);
    writeD(mapLimitList.size());
    Iterator<L1MapsLimitTime> iterator = mapLimitList.iterator();
    while (iterator.hasNext()) {
      L1MapsLimitTime mapLimit = iterator.next();
      int order_id = mapLimit.getOrderId();
      int used_time = pc.getMapsTime(order_id);
      int time_str = (mapLimit.getLimitTime() - used_time) / 60;
      writeD(order_id);
      writeS(mapLimit.getMapName());
      writeD(time_str);
    } 
  }
  
  public byte[] getContent() {
    if (this._byte == null)
      this._byte = getBytes(); 
    return this._byte;
  }
  
  public String getType() {
    return getClass().getSimpleName();
  }
}
